home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / tar / next / level-0 < prev    next >
Encoding:
Text File  |  1992-12-20  |  5.3 KB  |  166 lines

  1. #!/bin/sh
  2. #
  3. # Run this script as root on the machine that has the tape drive, to make a
  4. # full dump.
  5. #
  6. # If you give `now' as an argument, the dump is done immediately.
  7. # Otherwise, it waits until 1am, or until the hour given as argument.
  8. # Specify the hour as a number from 0 to 23.
  9. #
  10. # You must edit the file `backup-specs' to set the parameters for your site.
  11. #
  12. # Modifications by P. E. Cantrell to use remote tape from host
  13. # TAPE_HOST set in backup-specs-tape. Added variable
  14. # USERID to be the userid on the remote machine, also
  15. # set in backup-specs-tape. Also fixed problem with
  16. # >& construct in mkdir. Added new file $fsname.level-1-floppy
  17. # for use with level-2 floppy disk backups. We rewrite *.level-1-floppy
  18. # whenever we do a tape level-0 backup or a tape or floppy level-1
  19. # backup.
  20. #
  21. #set -vx
  22. if [ ! -w / ]; then
  23.    echo The backup must be run as root,
  24.    echo or else some files will fail to be dumped.
  25.    exit 1
  26. else
  27.    false
  28. fi
  29.  
  30. # This is undesirable -- rms.
  31. # rsh albert /usr/local/adm/motd-backup-start
  32.  
  33. # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
  34. . ./backup-specs-tape
  35.  
  36. # Maybe sleep until around specified or default hour.
  37. #
  38. if [ "$1" != "now" ]; then
  39.    if [ "$1"x != x ]; then
  40.       spec=$1
  41.    else
  42.       spec=$BACKUP_HOUR
  43.    fi
  44.    pausetime=`date | awk '{hr=substr($4,1,2);\\
  45.       mn=substr($4,4,2);\\
  46.       if((hr+0)<spec)\\
  47.          print 3600*(spec-hr)-60*mn;\\
  48.       else\\
  49.          print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
  50.    clear
  51.    cat ./dont_touch
  52.    sleep $pausetime
  53. fi
  54.  
  55. # start doing things
  56.  
  57. here=`pwd`
  58. LOGFILE=log-`date | awk '{print $2 "-" $3 "-" $6}'`-full
  59. HOST=`hostname | sed 's/\..*//'`
  60. #TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system +block=$BLOCKING +sparse"
  61. TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system \
  62.   +block=$BLOCKING "
  63.  
  64. # Make sure the log file did not already exist.  Create it.
  65.  
  66. if [ -f $LOGFILE ] ; then
  67.    echo Log file $LOGFILE already exists.
  68.    exit 1
  69. else
  70.    touch $LOGFILE
  71. fi
  72.  
  73. #mt -f $TAPE_FILE rewind
  74. rsh $TAPE_HOST -l $USERID mt rew    #PEC 6-1-91
  75.  
  76. if [ x != "x$BACKUP_DIRS" ] ; then
  77. set $BACKUP_DIRS
  78. while [ $# -ne 0 ] ; do
  79.    host=`echo $1 | sed 's/:.*$//'`
  80.    fs=`echo $1 | sed 's/^.*://'`
  81.    date=`date`
  82.    fsname=`echo $1 | sed 's/\//:/g'`
  83.  
  84.    TAR_PART2="+listed=/etc/tar-backup/temp.level-0"
  85.    TAR_PART3="+label='Full tape backup of $fs on $host at $date' -C $fs ."
  86.  
  87.    echo Backing up $1 at $date to tape | tee -a $LOGFILE
  88.  
  89.    # Actually back things up.
  90.  
  91.    if [ $HOST != $host ] ; then
  92.       rsh $host "mkdir /etc/tar-backup >&/dev/null; \
  93.     rm -f /etc/tar-backup/temp.level-0; \
  94.           $TAR_PART1 -f $USERID@$TAPE_HOST:$TAPE_FILE $TAR_PART2 $TAR_PART3" \
  95.      2>&1 | tee -a $LOGFILE
  96.    else
  97.       mkdir /etc/tar-backup 2>/dev/null >/dev/null
  98.       rm -f /etc/tar-backup/temp.level-0
  99. # Using `sh -c exec' causes nested quoting and shell substitution
  100. # to be handled here in the same way rsh handles it.
  101.       sh -c "exec $TAR_PART1 -f $USERID@$TAPE_HOST:$TAPE_FILE $TAR_PART2 \
  102.          $TAR_PART3" 2>&1 | tee -a $LOGFILE
  103.    fi
  104.    if [ $? -ne 0 ] ; then
  105.       echo Backup to tape of $1 failed. | tee -a $LOGFILE
  106.       # I'm assuming that the tar will have written an empty
  107.       # file to the tape, otherwise I should do a cat here.
  108.    else
  109.       if [ $HOST != $host ] ; then
  110.     rsh $host mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-0 2>&1 | tee -a $LOGFILE
  111.       else
  112.     cp /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-1-floppy 2>&1 | tee -a $LOGFILE
  113.         mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/$fsname.level-0 2>&1 | tee -a $LOGFILE
  114.       fi
  115.    fi
  116.    $TAPE_STATUS | tee -a $LOGFILE
  117.    sleep 60
  118.    shift
  119. done
  120. else
  121.   echo No Backup file systems specified |tee -a $LOGFILE
  122. fi
  123. # Dump any individual files requested.
  124.  
  125. if [ x != "x$BACKUP_FILES" ] ; then
  126.    date=`date`
  127.  
  128.    TAR_PART2="+listed=/etc/tar-backup/temp.level-0"
  129.    TAR_PART3="+label='level-0 tape backup of miscellaneous files at $date'"
  130.  
  131.    mkdir /etc/tar-backup 2>/dev/null >/dev/null
  132.    rm -f /etc/tar-backup/temp.level-0
  133.  
  134.    echo Backing up level-0 to tape miscellaneous directories and files at $date | tee -a $LOGFILE
  135.    echo "Directories and files:" | tee -a $LOGFILE
  136.    echo $BACKUP_FILES | tee -a $LOGFILE
  137.    echo " " | tee -a $LOGFILE
  138. # Using `sh -c exec' causes nested quoting and shell substitution
  139. # to be handled here in the same way rsh handles it.
  140.    sh -c "exec $TAR_PART1 -f $USERID@$TAPE_HOST:$TAPE_FILE $TAR_PART2 \
  141.     $TAR_PART3 $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
  142.    if [ $? -ne 0 ] ; then
  143.      echo Backup of level-0 to tape of miscellaneous directories and files failed. | tee -a $LOGFILE
  144.      # I'm assuming that the tar will have written an empty
  145.      # file to the tape, otherwise I should do a cat here.
  146.    else
  147.      cp /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-1-floppy 2>&1 | tee -a $LOGFILE
  148.      mv -f /etc/tar-backup/temp.level-0 /etc/tar-backup/misc.level-0 2>&1 | tee -a $LOGFILE
  149.    fi
  150.    $TAPE_STATUS | tee -a $LOGFILE
  151. else
  152.    echo No miscellaneous directories or files specified | tee -a $LOGFILE
  153.    false
  154. fi
  155.  
  156. #mt -f $TAPE_FILE rewind
  157. #mt -f $TAPE_FILE offl
  158. rsh $TAPE_HOST -l $USERID mt rew
  159.  
  160. echo Sending the dump log to $ADMINISTRATOR
  161. #cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
  162. /usr/ucb/mail -s "Results of level-0 tape backup on `date`" $ADMINISTRATOR < $LOGFILE
  163.  
  164. # This is undesirable -- rms.
  165. #rsh albert /usr/local/adm/motd-backup-done &
  166.